package com.dotflat.check.domain.C.PO;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.util.Date;
import java.util.List;

@Data
@XmlRootElement(name = "GetAttendanceUserResult")  // 父节点名称
@XmlAccessorType(XmlAccessType.FIELD) //定义这个类中的何种类型需要映射到XML
public class GetAttendanceUserResult {

    @XmlElement(name = "AutoSendMsg")
    @JSONField(name = "AutoSendMsg")
    Integer AutoSendMsg = 0;
    @XmlElement(name = "BirthDay")
    @JSONField(name = "BirthDay")
    String BirthDay = "2000-01-01 00:00:00";
    @XmlElement(name = "BroadcastName")
    @JSONField(name = "BroadcastName")
    String BroadcastName = "";
    @XmlElement(name = "CampusNo")
    @JSONField(name = "CampusNo")
    String CampusNo = "";
    @XmlElement(name = "ClassInfoID")
    @JSONField(name = "ClassInfoID")
    String ClassInfoID = "0";
    @XmlElement(name = "ClassName")
    @JSONField(name = "ClassName")
    String ClassName = "";
    @XmlElement(name = "HeadImage")
    @JSONField(name = "HeadImage")
    String HeadImage = "";
    @XmlElement(name = "KgId")
    @JSONField(name = "KgId")
    String KgId;
    @XmlElement(name = "MonitorInfo")
    @JSONField(name = "MonitorInfo")
    String MonitorInfo = null;
    @XmlElement(name = "Note")
    @JSONField(name = "Note")
    String Note = "";
    @XmlElement(name = "SACardNo")
    @JSONField(name = "SACardNo")
    String SACardNo = "";
    @XmlElement(name = "Sex")
    @JSONField(name = "Sex")
    Integer Sex = 0;
    @XmlElement(name = "State")
    @JSONField(name = "State")
    Integer State = 1;
    @XmlElement(name = "UserId")
    @JSONField(name = "UserId")
    String UserId;
    @XmlElement(name = "UserName")
    @JSONField(name = "UserName")
    String UserName;
    @XmlElement(name = "UserType")
    @JSONField(name = "UserType")
    Integer UserType = 0;
    @XmlElement(name = "WorkerExtensionId")
    @JSONField(name = "WorkerExtensionId")
    Integer WorkerExtensionId = 0;


    /**
     * 将对象转为流程XML
     *
     * @return
     * @throws JAXBException
     */
    public static String convertToXML(List<GetAttendanceUserResult> list) {
        String data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" +
                "    <soap:Body>\n" +
                "         <GetAttendanceUserResponse xmlns=\"http://tempuri.org/\">\n" +
                "            <GetAttendanceUserResult>${v}</GetAttendanceUserResult>\n" +
                "        </GetAttendanceUserResponse>" +
                "  </soap12:Body>\n" +
                "</soap12:Envelope>";
        String xmlStr = JSON.toJSONString(list);
        data = data.replace("${v}", xmlStr);
        return data;
    }

}
